package com.whitedust.top100;

import com.whitedust.structure.ListNode;

/**
 *
 * @author A
 * @since 2025/11/17 19:13
 */

public class Top96 {
    public ListNode swapPairs(ListNode head) {
        if (head == null) return null;
        ListNode dummy = new ListNode(0, head);
        ListNode pre = dummy;
        ListNode start = head;
        ListNode end = head.next;
        ListNode next = null;
        while (end != null) {
            next = end.next;
            pre.next = end;
            end.next = start;
            start.next = next;
            pre = start;
            start = next;
            if (start == null) break;
            end = start.next;
        }
        return dummy.next;
    }
}
